﻿using System.Collections;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Collections.Generic
{
    [TestClass]
    public class WhenDeterminingIfEnumerablesHaveSameElements
    {
        [TestMethod]
        public void ShouldReturnTrueWhenGenericEnumerablesHaveSameElements()
        {
            IEnumerable<int> enumeration1 = new int[] {1, 2, 3};
            IEnumerable<int> enumeration2 = new int[] {1, 2, 3};

            Assert.IsTrue(EnumerableHelper.HaveSameElements(enumeration1, enumeration2, EqualityComparer<int>.Default.Equals));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenGenericEnumerablesDoNotHaveSameElements()
        {
            IEnumerable<int> enumeration1 = new int[] {1, 2, 3};
            IEnumerable<int> enumeration2 = new int[] {1, 7, 3};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2, EqualityComparer<int>.Default.Equals));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenFirstGenericEnumerableHasMoreElements()
        {
            IEnumerable<int> enumeration1 = new int[] {1, 2, 3, 4};
            IEnumerable<int> enumeration2 = new int[] {1, 2, 3};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2, EqualityComparer<int>.Default.Equals));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenSecondGenericEnumerableHasMoreElements()
        {
            IEnumerable<int> enumeration1 = new int[] {1, 2, 3};
            IEnumerable<int> enumeration2 = new int[] {1, 2, 3, 4};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2, EqualityComparer<int>.Default.Equals));
        }

        [TestMethod]
        public void ShouldReturnTrueWhenBothEnumerablesHaveSameElements()
        {
            IEnumerable enumeration1 = new int[] {1, 2, 3};
            IEnumerable enumeration2 = new int[] {1, 2, 3};

            Assert.IsTrue(EnumerableHelper.HaveSameElements(enumeration1, EnumerableHelper.Convert<int>(enumeration2)));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenBothEnumerablesHaveNotSameElements()
        {
            IEnumerable enumeration1 = new int[] {1, 2, 3};
            IEnumerable enumeration2 = new int[] {1, 7, 3};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenFirstEnumerableHasMoreElements()
        {
            IEnumerable enumeration1 = new int[] {1, 2, 3, 4};
            IEnumerable enumeration2 = new int[] {1, 2, 3};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2));
        }

        [TestMethod]
        public void ShouldReturnFalseWhenSecondEnumerableHasMoreElements()
        {
            IEnumerable enumeration1 = new int[] {1, 2, 3};
            IEnumerable enumeration2 = new int[] {1, 2, 3, 4};

            Assert.IsFalse(EnumerableHelper.HaveSameElements(enumeration1, enumeration2));
        }
    }
}